package org.linlinjava.litemall.admin.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.service.AdminPiccMessageService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.PiccMessagePackage;
import org.linlinjava.litemall.db.service.PiccMessagePackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/messages")
@Validated
public class PiccMessageController {
    @Autowired
    AdminPiccMessageService adminPiccMessageService;
    @Autowired
    PiccMessagePackageService messagePackageService;

    @PostMapping("/create")
    public Object addMessage(@RequestBody PiccMessagePackage message){
        PiccMessagePackage msg = adminPiccMessageService.add(message);
        return ResponseUtil.ok(msg);
    }

    @GetMapping("/content")
    public Object getList(@RequestParam Integer patientId,
                          @RequestParam Integer nurseId,
                          @RequestParam String sender,
                          @Sort @RequestParam(defaultValue = "add_time") String sort,
                          @RequestParam(defaultValue = "asc") String order){
        return adminPiccMessageService.contentByIds(patientId, nurseId, sender, sort, order);
    }

    @RequiresPermissions("admin:messages:infolist")
    @RequiresPermissionsDesc(menu = {"消息管理", "消息预览"}, button = "查询")
    @GetMapping("/infolist")
    public Object getList(@RequestParam Integer patientId,
                          @RequestParam Integer nurseId,
                          @RequestParam String sender){
        return adminPiccMessageService.listByNurse(nurseId, patientId, sender);
    }
}
